package com.neelsys.visualisation.repository.majorComb;

import static org.neo4j.cypherdsl.CypherQuery.collect;
import static org.neo4j.cypherdsl.CypherQuery.distinct;
import static org.neo4j.cypherdsl.CypherQuery.has;
import static org.neo4j.cypherdsl.CypherQuery.identifier;
import static org.neo4j.cypherdsl.CypherQuery.literal;
import static org.neo4j.cypherdsl.CypherQuery.lookup;
import static org.neo4j.cypherdsl.CypherQuery.node;
import static org.neo4j.cypherdsl.CypherQuery.start;
import static org.neo4j.cypherdsl.querydsl.CypherQueryDSL.identifier;
import static org.neo4j.cypherdsl.querydsl.CypherQueryDSL.toBooleanExpression;

import java.util.HashMap;

import org.neo4j.cypherdsl.Identifier;
import org.neo4j.cypherdsl.expression.StartExpression.StartNodesLookup;
import org.neo4j.cypherdsl.grammar.Execute;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.neo4j.conversion.EndResult;
import org.springframework.data.neo4j.support.Neo4jTemplate;

import com.neelsys.visualisation.domain.CourseLevelEnum;
import com.neelsys.visualisation.domain.MajorCombination;
import com.neelsys.visualisation.domain.QMajorCombination;

public class MajorCombinationRepositoryImpl implements
		MajorCombinationExtensionRepo {

	@Autowired
	MajorCombinationRepository repo;

	@Autowired
	Neo4jTemplate template;

	@Override
	public MajorCombination sampleCypherDsl(String courseIdentifier) {
		QMajorCombination qmajorCombination = QMajorCombination.majorCombination;

		StartNodesLookup nodeLookup = lookup(identifier(qmajorCombination),
				identifier("MajorCombination"),
				identifier(qmajorCombination.courseIdentifier),
				literal(courseIdentifier));

		Identifier majorCombResult = identifier("majorCombResult");

		// look
		Execute query = start(nodeLookup)
				.match(node(identifier(qmajorCombination)).in().hops(1, 5)
						.node(majorCombResult))
				.where(has(majorCombResult
						.property(identifier(qmajorCombination.courseIdentifier))))
				.returns(distinct(collect(majorCombResult)));

		System.out.println(query);

		EndResult<MajorCombination> endResults = repo.query(query,
				new HashMap<String, Object>());

		endResults.finish();

		return null;

	}

	@Override
	public MajorCombination sampleCypherDsl1(String courseIdentifier) {

		// look
		String query = "START majorCombination=node:MajorCombination(courseIdentifier=\""
				+ courseIdentifier
				+ "\") MATCH (majorCombination)<-[*1..5]-(majorCombResult) WHERE has(majorCombResult.courseIdentifier) RETURN DISTINCT collect(majorCombResult),count(*)";

		System.out.println(query);

		EndResult<MajorCombination> endResults = repo.query(query,
				new HashMap<String, Object>());

		// MajorCombination obj = endResults.iterator().next();

		return null;

	}
}
